--File ： ChapterView.lua
--Author : zee
--Date   : 2015/4/8
--Description : 主界面，从scene来，用于组织所有的layer，层级等等。




PlayEndNode = class("PlayEndNode",function()
    -- 继承
    local ret = cc.Layer:create()

    ret.clickFunc = 1

    ret.start = nil
    return ret
end)

PlayEndNode.__index = PlayEndNode


function PlayEndNode:create()
    local ret = PlayEndNode:new()
    return ret
end




--------------------------------------------------------
-- 初始化
--------------------------------------------------------
function PlayEndNode:start()
    -- 
    self.backLayer = cc.LayerColor:create()
    self.backLayer:setColor( cc.c3b(0,0,0) )
    self.backLayer:setOpacity( 255 )
    self:addChild( self.backLayer )

    self:makeUI()
    self:showAnimate()
end




function PlayEndNode:makeUI()
    self.rootNode = cc.CSLoader:createNode("csb/play/playEnd.csb")
    self:addChild( self.rootNode )

    self.txt_success = SearchChildByName( self.rootNode, "txt_success" )
    self.txt_fail = SearchChildByName( self.rootNode, "txt_fail" )
    --  event
    self.btn_full = SearchChildByName( self.rootNode, "base" )
    local function clickEvt()
        self:onClick()
    end
    AddTouchEvent( self.btn_full,  clickEvt, UI:getInstance(),  nil, nil, nil )

    -- 添加逐帧方法:
    local function frameEvent(dt) 
        self:onFrame(dt) 
    end
    -- self:scheduleUpdateWithPriorityLua( frameEvent, 0 )
end


function PlayEndNode:onFrame(dt)
    cclook(" self.score: %s", self.score )
end



function PlayEndNode:onClick()
    Sound(9)
    cclog(" hehe : %s ", self.clickFunc~=nil )
    if( self.clickFunc~=nil )then
        cclog("日你妈， 执行了")
        self.clickFunc()
    end
end


function PlayEndNode:setClickEvt(evt)
    self.clickFunc = evt
    cclog(" hehe : %s ", self.clickFunc~=nil )
end




function PlayEndNode:setGameEndInfo( isWin, score )
    self.txt_fail:setString(" 游戏失败 得分 : "..score)
    self.txt_success:setString(" 游戏胜利 得分 : "..score)
    self.score = score
    if(isWin) then 
        self.txt_fail:setVisible(false)
    else
        self.txt_success:setVisible(false)
    end
end


function PlayEndNode:showAnimate()
    self.rootNode:setVisible(false)
    self.backLayer:setOpacity(0)
    local fad = cc.FadeIn:create(1)
    local function showEvt()
        self.rootNode:setVisible(true)
    end
    local show = cc.CallFunc:create(showEvt)
    local seq = cc.Sequence:create( fad, show);
    self.backLayer:runAction(seq)
end












